//
//  NSObject+BSNetworking.m
//  sister
//
//  Created by 周冰烽 on 2017/2/14.
//  Copyright © 2017年 周冰烽. All rights reserved.
//

#import "NSObject+BSNetworking.h"

#define BSTimeoutInterval 10

@implementation NSObject (BSNetworking)
+(id)GET:(NSString *)path parameters:(NSDictionary *)parameters progress:(void(^)(NSProgress * downloadProgress))downloadProgress completionHandler:(void (^)(id, NSError *))completionHandler{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"text/json",@"text/javascript",@"application/json", nil];
    //请求时间超时
    manager.requestSerializer.timeoutInterval = BSTimeoutInterval;
    return [manager GET:path parameters:parameters progress:downloadProgress success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        completionHandler(responseObject,nil);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        completionHandler(nil,error);
    }];
}

+(id)POST:(NSString *)path parameters:(NSDictionary *)parameters progress:(void(^)(NSProgress * downloadProgress))downloadProgress completionHandler:(void (^)(id, NSError *))completionHandler{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"text/json",@"text/javascript",@"application/json", nil];
    //请求时间超时
    manager.requestSerializer.timeoutInterval = BSTimeoutInterval;
    return [manager POST:path parameters:parameters progress:downloadProgress success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        completionHandler(responseObject,nil);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        completionHandler(nil,error);
    }];
    
}
@end
